

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 角色管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../../static/bootstrap.min.css" media="all">
  <link rel="stylesheet" href="../../../static/style.css" media="all">
  <link rel="stylesheet" href="../../../static/H-ui.min.css" media="all">
  <link rel="stylesheet" href="../../../static/H-ui.admin.css" media="all">
  
  <link rel="stylesheet" href="../../../static/icheck.css" media="all">
  <link rel="stylesheet" href="../../../static/iconfont.css" media="all">
  
</head>
<style>
    #form1 input{display:inline-block !important;}
    .permission-list2 dd label{
	    font-weight: 
}
.layui-form-label{width:100px;]}
.permission-list > dd {
    padding: 5px 5px 5px 10px;
}
.layui-input-9{
	    width: 90%;
	margin-left:10px;
}
 </style>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
    
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
         <!--  <button class="layui-btn layuiadmin-btn-role layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
          <button class="layui-btn layuiadmin-btn-role layuiadmin-btn-useradmin" data-type="add">添加</button> -->
        </div>

        <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>
      
      </div>
    </div>
  </div>

 <script src="../../../layuiadmin/layui/layui.js"></script>
   <script src="../../../layuiadmin/layui/layui.all.js"></script>  
   <script src="../../../layuiadmin/config.js"></script> 
  <script>
    layui.use(['table'], function(){
      var $ = layui.$
              ,form = layui.form
              ,table = layui.table;
      var tableIns = table.render({
        elem: '#LAY-user-back-role',
        url : "{:url('lists')}",
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limits : [10,40,100,500,1000],
        limit : 10,
        id : "LAY-user-manage",
        cols : [[
          {checkbox: true},
          {field: 'id', title: 'ID', minWidth:100, align:"center"},
          {field: 'user1', title: '参赛用户1/得分', align:'center',minWidth:80,templet:function(d){
        	  return d.user1+'/'+d.uid1_score;
          }},
          {field: 'user2', title: '参赛用户2/得分', align:'center',minWidth:80,templet:function(d){
        	  return d.user2+'/'+d.uid2_score;
          }},
          {field: 'reward', title: '奖励', align:'center',minWidth:80},
          {field: 'create_time', title: '比赛时间', align:'center',minWidth:80,templet:function(d){
        	  return timeStamp2String(d.create_time*1000);
          }},
          {field: 'grade', title: '题目难易星级', align:'center',minWidth:80},
/*           {field: '', title: '操作', align:'center'}, */
        ]]
      });
      //监听搜索
      form.on('submit(LAY-user-front-search)', function(data){
        var field = data.field;
        console.log(field);
        //执行重载
        table.reload('LAY-user-manage',{
          url: "{:url('lists?op=table')}",
          where : field,
          done: function(res, curr, count){
            //如果是异步请求数据方式，res即为你接口返回的信息。
            //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
            console.log(res);
            //得到当前页码
//                console.log(curr);
            //得到数据总量
//                console.log(count);
          }
        });
      });

      //事件
      var active = {  
        batchdel: function(){
          var checkStatus = table.checkStatus('LAY-user-manage')
                  ,checkData = checkStatus.data; //得到选中的数据
                 
          if(checkData.length === 0){
            return layer.msg('请选择数据');
          }
                  ajax_data = [];
		$.each(checkData,function(k,v){
			ajax_data.push(v.id);
		})
          layer.confirm('确定删除吗？', function(index) {
              //console.log(ajax_data)
              $.ajax({
            		type: 'POST',
    	            url: '{:url("del")}',
    	            data: {id:ajax_data},
    	            dataType: 'json',
    	            timeout: 3000,
    	            success: function (data) {
    	         	   console.log(data)
    	         	   if(data.code==0){
    	         		  table.reload('LAY-user-manage'); //数据刷新
    	                  layer.closeAll(); //关闭弹层
    	                  layer.msg(data.msg);
    	         	   }else{
    	         		  layer.msg(data.msg);
    	         	   }
    	            }
            	});
            });
        }
        ,add: function(){
        	str_menu = '';
        	id = $(this).data('id');data = $(this).data('data');
        	if(id){
        		this_url = 'edit/id/'+id+'.html';
        	}else{
        		this_url = '{:url("add")}';
        	}
        	//console.log(this_url)
          content = '<div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">'+
        '<form id="form1"><div class="layui-form-item">'+
          '<label class="layui-form-label">题目</label>'+
         ' <div class="layui-input-block">'+
          '  <textarea  name="content" class="layui-textarea">'+data_null(data?data.content:'')+'</textarea>'+
          '</div>'+
       ' </div>'+
       '<div class="layui-form-item">'+
       '<label class="layui-form-label">答案</label>'+
      ' <div class="layui-input-block">'+
       '<li><input type="radio" name="answer" '+data_checked(data.answer,1)+' value="1" class="layui-radio">A<input type="text" name="question[1]" value="'+data_null(data?data.question[1]:'')+'" class="layui-input layui-input-9"></li>'+
       '<li><input type="radio" name="answer" '+data_checked(data.answer,2)+' value="2" class="layui-radio">B<input type="text" name="question[2]" value="'+data_null(data?data.question[2]:'')+'" class="layui-input layui-input-9"></li>'+
       '<li><input type="radio" name="answer" '+data_checked(data.answer,3)+' value="3" class="layui-radio">C<input type="text" name="question[3]" value="'+data_null(data?data.question[3]:'')+'" class="layui-input layui-input-9"></li>'+
       '<li><input type="radio" name="answer" '+data_checked(data.answer,4)+' value="4" class="layui-radio">D<input type="text" name="question[4]" value="'+data_null(data?data.question[4]:'')+'" class="layui-input layui-input-9"></li>'+
       '</div>'+
    ' </div>'+
    '<div class="layui-form-item">'+
    '<label class="layui-form-label">题目类型</label>'+
    ' <div class="layui-input-block">'+
    '<select class="layui-select" style="display:block;" name="type"><option value="">-请选择-</option>'+
    '<option '+data_selected(data.type,1)+' value="1">生活类</option><option '+data_selected(data.type,2)+' value="2">文学类</option><option '+data_selected(data.type,3)+' value="3">政治类</option>'+
    '<option '+data_selected(data.type,4)+' value="4">历史类</option><option '+data_selected(data.type,5)+' value="5">地理类</option><option '+data_selected(data.type,6)+' value="6">娱乐类</option>'+
    '</select>'
    '</div>'+
 ' </div>'+
'</form>'+
     ' </div>';
          layer.open({
            type: 1
            ,title: '添加角色'
            ,content: content
            ,maxmin: true
            ,area: ['960px', '80%']
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
            	$.ajax({
            		type: 'POST',
    	            url: this_url,
    	            data: $('#form1').serialize(),
    	            dataType: 'json',
    	            timeout: 3000,
    	            success: function (data) {
    	         	   //console.log(data)
    	         	   if(data.code==0){
    	         		  table.reload('LAY-user-manage'); //数据刷新
    	                  layer.closeAll(); //关闭弹层
    	                  layer.msg(data.msg);
    	         	   }else{
    	         		  layer.msg(data.msg);
    	         	   }
    	            }
            	});
            	
            }
          });
        }
      };

      $('body').on('click','.layui-btn.layuiadmin-btn-useradmin', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
      });
    });

  </script>
</body>
</html>

